home *** CD-ROM | disk | FTP | other *** search
- Path: baggins.cc.flinders.edu.au!usenet
- From: "T. Gruber" <gruber@es.flinders.edu.au>
- Newsgroups: comp.lang.c++
- Subject: Why? Virtual member causes General Protection Exception
- Date: Mon, 15 Apr 1996 19:21:38 -0700
- Organization: Flinders University
- Message-ID: <31730432.28C@es.flinders.edu.au>
- NNTP-Posting-Host: geophone.es.flinders.edu.au
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- Hi
-
- I can compile and run the appended code (BC++ 4.5; Win 3.11), but it causes a
- General Protection Exception in the last line. Why?
-
- A::y() does call B::x(), but this code does not get the right address for B::i. I
- assume I am at fault, but I can't find a documented reference that tells me so. Am
- *I* stupid?
-
- Please email a copy of your reply.
-
- Thanks
-
- Thomas
-
- #include <iostream.h>
-
- class A {
- public:
- virtual void x() = 0;
- void y() { x(); };
- };
-
- class B : public virtual A {
- public:
- B() : i(0) {};
- virtual void x() { cout << i << endl; };
- int i;
- };
-
- class C : public virtual A, public virtual B {};
-
- void main()
- {
- C c1;
- C c2(c1);
- c2.x(); // works
- c2.y(); // crashes in B::x()
- }
-